cmake_minimum_required(VERSION 3.0.2)
project(dog_control)

if(NOT WIN32)
  string(ASCII 27 Esc)
  set(ColourReset "${Esc}[m")
  set(ColourBold  "${Esc}[1m")
  set(Red         "${Esc}[31m")
  set(Green       "${Esc}[32m")
  set(Yellow      "${Esc}[33m")
  set(Blue        "${Esc}[34m")
  set(Magenta     "${Esc}[35m")
  set(Cyan        "${Esc}[36m")
  set(White       "${Esc}[37m")
  set(BoldRed     "${Esc}[1;31m")
  set(BoldGreen   "${Esc}[1;32m")
  set(BoldYellow  "${Esc}[1;33m")
  set(BoldBlue    "${Esc}[1;34m")
  set(BoldMagenta "${Esc}[1;35m")
  set(BoldCyan    "${Esc}[1;36m")
  set(BoldWhite   "${Esc}[1;37m")
endif()

# message("This is normal")
# message("${Red}This is Red${ColourReset}")
# message("${Green}This is Green${ColourReset}")
# message("${Yellow}This is Yellow${ColourReset}")
# message("${Blue}This is Blue${ColourReset}")
# message("${Magenta}This is Magenta${ColourReset}")
# message("${Cyan}This is Cyan${ColourReset}")
# message("${White}This is White${ColourReset}")
# message("${BoldRed}This is BoldRed${ColourReset}")
# message("${BoldGreen}This is BoldGreen${ColourReset}")
# message("${BoldYellow}This is BoldYellow${ColourReset}")
# message("${BoldBlue}This is BoldBlue${ColourReset}")
# message("${BoldMagenta}This is BoldMagenta${ColourReset}")
# message("${BoldCyan}This is BoldCyan${ColourReset}")
# message("${BoldWhite}This is BoldWhite\n\n${ColourReset}")

# check arch and os  检查系统
message("--${BoldGreen} CMAKE_SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}${ColourReset}")
if("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "x86_64.*")
  set(ARCH amd64)
  message("--${BoldGreen} ARCH: ${ARCH}${ColourReset}")
endif()
if("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "aarch64.*")
  set(ARCH arm64)
  message("--${BoldGreen} ARCH: ${ARCH}${ColourReset}")
endif()

## Compile as C++11
add_compile_options(-std=c++11)
set(CMAKE_CXX_FLAGS "-O3")

## Find catkin macros and libraries
find_package(catkin REQUIRED COMPONENTS
  roscpp
  tf
  std_msgs
  roslib  # for using ros::package

  geometry_msgs
  # controller_manager
  message_generation
)

add_message_files(FILES dog_info.msg)
generate_messages(DEPENDENCIES std_msgs)

catkin_package(
  CATKIN_DEPENDS 
  roscpp 
  std_msgs
  roslib
  geometry_msgs
  message_runtime
  tf
)

include_directories(
  ${catkin_INCLUDE_DIRS}
  )

include_directories(${PROJECT_SOURCE_DIR}/sdk/unitree_legged_sdk/include)
link_directories(${PROJECT_SOURCE_DIR}/sdk/unitree_legged_sdk/lib/cpp/${ARCH})
# link_directories(${PROJECT_SOURCE_DIR}/sdk/unitree_legged_sdk/lib/cpp/amd64)
# link_directories(${PROJECT_SOURCE_DIR}/sdk/unitree_legged_sdk/lib/cpp/arm64)
message("--${BoldGreen} link_directories path : ${PROJECT_SOURCE_DIR}/sdk/unitree_legged_sdk/lib/cpp/${ARCH} ${ColourReset}")

set(EXTRA_LIBS -pthread libunitree_legged_sdk.a lcm)

add_executable(dog_control src/dog_control_for_go1.cpp)
target_link_libraries(dog_control  ${catkin_LIBRARIES} ${EXTRA_LIBS} ${OpenCV_LIBS})

add_executable(teleop_twist_keyboard src/teleop_twist_keyboard.cpp)
target_link_libraries(teleop_twist_keyboard ${catkin_LIBRARIES})
